package ${serviceInfo.projectInfo.groupId}.controller.${urlPrefix}.${serviceInfo.serviceName?lower_case};

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import ${serviceInfo.projectInfo.groupId}.dal.mybatis.model.${serviceInfo.modelName?cap_first};
import ${serviceInfo.serviceClazz?lower_case}.dto.${serviceInfo.serviceName?cap_first}AddItemReq;
import ${serviceInfo.serviceClazz?lower_case}.dto.${serviceInfo.serviceName?cap_first}UpdateItemReq;
import ${serviceInfo.projectInfo.groupId}.service.${serviceInfo.serviceName?lower_case}.${serviceInfo.serviceName?cap_first}Service;
import ${serviceInfo.projectInfo.groupId}.service.${serviceInfo.serviceName?lower_case}.dto.${serviceInfo.serviceName?cap_first}QueryFilter;
import com.system.core.controller.ControllerBase;
import com.system.core.results.ResultBase;
import com.system.core.view.layui.table.TableViewRspDto;

@Controller
@RequestMapping("${urlPrefix}/${baseUrl}")
public class ${serviceInfo.serviceName?cap_first}Controller extends ControllerBase {
	<#list serviceInfo.columns as item>
	<#if item.prikey>
	<#assign priname="${item.javaCode?cap_first}"/>
	<#assign priType="${item.javaType}"/>
	</#if>
	</#list>
	@Autowired
	private ${serviceInfo.serviceName?cap_first}Service ${serviceInfo.serviceName?uncap_first}Service;
	
	@RequiresPermissions("${serviceInfo.serviceName?uncap_first}_topage")
	@RequestMapping(value = "to_page",method = RequestMethod.GET)
	public String toPage() {
		<#list serviceInfo.columns as item>
		<#if item.enumInfo??>
		getModelMap().put("${item.tableClazzCode?uncap_first}${item.javaCode?cap_first}Enum", ${item.projectInfo.groupId}.dal.mybatis.enums.${item.tableClazzCode}${item.javaCode?cap_first}Enum.getAllEnum());
		</#if>
		</#list>
		return "/${urlPrefix}/${serviceInfo.serviceName}/${serviceInfo.serviceName}-list";
	}
	
	@RequestMapping(value = "query_list",method = RequestMethod.POST)
	@ResponseBody
	public TableViewRspDto<${serviceInfo.modelName}> ${serviceInfo.serviceName?uncap_first}QueryList(${serviceInfo.serviceName?cap_first}QueryFilter filter) {
		TableViewRspDto<${serviceInfo.modelName}> rsp = ${serviceInfo.serviceName?uncap_first}Service.${serviceInfo.serviceName?uncap_first}List(filter);
		return rsp;
	}
	
	@RequestMapping(value = "get_item_by_key",method = RequestMethod.POST)
	@ResponseBody
	public ${serviceInfo.modelName} ${serviceInfo.serviceName?uncap_first}GetByPrimaryKey(${serviceInfo.modelName} ${serviceInfo.modelName?uncap_first}){
		return ${serviceInfo.serviceName?uncap_first}Service.${serviceInfo.serviceName?uncap_first}GetByPrimaryKey(${serviceInfo.modelName?uncap_first});
	}
	
	@RequiresPermissions("${serviceInfo.serviceName?uncap_first}_add_opt")
	@RequestMapping(value = "add_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase ${serviceInfo.serviceName?uncap_first}AddItem(@Validated ${serviceInfo.serviceName?cap_first}AddItemReq ${serviceInfo.serviceName?uncap_first}AddItemReqDto) {
		return ${serviceInfo.serviceName?uncap_first}Service.${serviceInfo.serviceName?uncap_first}Save(${serviceInfo.serviceName?uncap_first}AddItemReqDto);
	}
	
	@RequiresPermissions("${serviceInfo.serviceName?uncap_first}_edit_opt")
	@RequestMapping(value = "update_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase ${serviceInfo.serviceName?uncap_first}UpdateItem(@Validated ${serviceInfo.serviceName?cap_first}UpdateItemReq ${serviceInfo.serviceName?uncap_first}UpdateItemReqDto) {
		return ${serviceInfo.serviceName?uncap_first}Service.${serviceInfo.serviceName?uncap_first}UpdateByPrimaryKey(${serviceInfo.serviceName?uncap_first}UpdateItemReqDto);
	}
	
	@RequiresPermissions("${serviceInfo.serviceName?uncap_first}_delete_opt")
	@RequestMapping(value = "delete_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase ${serviceInfo.serviceName?uncap_first}DeleteItem(@RequestBody List<${priType}> keys) {
		return ${serviceInfo.serviceName?uncap_first}Service.${serviceInfo.serviceName?uncap_first}DeleteByPrimaryKey(keys);
	}
}
